package com.ansion.basedb.dao.model;

import androidx.annotation.NonNull;

import com.ansion.log.VLog;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;

public class UserModelExtra implements Serializable, Cloneable {
    static final String JSON_KEY_MODEL = "UserModelExtra";
    static final String JSON_KEY_IS_WALLET = "isWallet";
    static final String JSON_KEY_WALLET_EXPIRE_TIME = "walletExpireTime";

    public Long walletExpireTime;
    public Boolean isWallet;

    public static UserModelExtra fromJson(@NonNull JSONObject jsonObject) {
        JSONObject modelObject = jsonObject.optJSONObject(JSON_KEY_MODEL);
        UserModelExtra model = null;
        if (modelObject != null) {
            model = new UserModelExtra();
            model.walletExpireTime = modelObject.optLong(JSON_KEY_WALLET_EXPIRE_TIME);
            model.isWallet = modelObject.optBoolean(JSON_KEY_IS_WALLET);
        }
        return model;
    }

    public void buildJson(@NonNull JSONObject jsonObject) throws JSONException {
        JSONObject modelObject = new JSONObject();
        modelObject.put(JSON_KEY_WALLET_EXPIRE_TIME, walletExpireTime);
        modelObject.put(JSON_KEY_IS_WALLET,isWallet);
        jsonObject.put(JSON_KEY_MODEL, modelObject);
    }

    @NonNull
    @Override
    public UserModelExtra clone() {
        UserModelExtra o = null;
        try {
            o = (UserModelExtra) super.clone();
        } catch (Exception e) {
            VLog.e("TAG_LOG_ERROR", e);
        }
        return o;
    }
}
